#include "SoundEffectHandler.h"

SoundEffectHandler* SoundEffectHandler::m_pInstance = nullptr;

SoundEffectHandler::SoundEffectHandler() {
	FMOD_RESULT result;

	// inilialize FMOD system
	result = FMOD::System_Create(&m_pFmodSystem);
	result = m_pFmodSystem->init(512, FMOD_INIT_NORMAL, nullptr);

	// load start sound
	result = m_pFmodSystem->createSound("asset/aut.mp3", FMOD_DEFAULT, nullptr, &m_pStartSound);
	m_pFmodSystem->playSound(m_pStartSound, nullptr, false, nullptr);


	// load background sound
	result = m_pFmodSystem->createSound("asset/drumloop.wav", FMOD_DEFAULT, nullptr, &m_pBackgroundSound);
	m_pBackgroundChannel = nullptr;


	// load bullet sound
	result = m_pFmodSystem->createSound("asset/Vrhiatta.mp3", FMOD_DEFAULT, nullptr, &m_pBulletSound);

	//load gameover sound
	result = m_pFmodSystem->createSound("asset/Taunt01.mp3", FMOD_DEFAULT, nullptr, &m_pGameoverSound);
	result = m_pFmodSystem->createSound("asset/Taunt02.mp3", FMOD_DEFAULT, nullptr, &m_pGameoverSound2);

	//load tank moving sound as instruction scene bgm
	result = m_pFmodSystem->createSound("asset/tank_moving.mp3", FMOD_DEFAULT, nullptr, &m_pInstructionSound);
	// set loop
	m_pInstructionSound->setMode(FMOD_LOOP_NORMAL);

	result = m_pFmodSystem->createSound("asset/attacking.mp3", FMOD_DEFAULT, nullptr, &m_pLogoSound);


}

void SoundEffectHandler::PlayBGM() {
	m_pFmodSystem->playSound(m_pBackgroundSound, nullptr, false, &m_pBackgroundChannel);
}
void SoundEffectHandler::PauseBGM() {
	m_pBackgroundChannel->setPaused(true);
}
void SoundEffectHandler::PlaySplash() {
	m_pFmodSystem->playSound(m_pStartSound, nullptr, false, nullptr);

}
void SoundEffectHandler::PlayInstruction() {
	m_pFmodSystem->playSound(m_pInstructionSound, nullptr, false, &m_pInstructionChannel);
	m_pInstructionChannel->setPitch(0.6);
}
void SoundEffectHandler::PlayLogo() {
	m_pFmodSystem->playSound(m_pLogoSound, nullptr, false, nullptr);
}
void SoundEffectHandler::PauseInstruction() {
	m_pInstructionChannel->setPaused(true);
}
void SoundEffectHandler::PlayBullet() {
	m_pFmodSystem->playSound(m_pBulletSound, nullptr, false, nullptr);
}
void SoundEffectHandler::PlayGameover() {
	m_pFmodSystem->playSound(m_pGameoverSound, nullptr, false, nullptr);
	m_pFmodSystem->playSound(m_pGameoverSound2, nullptr, false, nullptr);
}
void SoundEffectHandler::Update() {
	m_pFmodSystem->update();//important for sound system

}